package org.tong;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(TongProperties.class)
@ConditionalOnClass(TongService.class)
@ConditionalOnProperty(prefix = "spring.tong", value = {"name", "ip", "port"}, matchIfMissing = false)
public class TongAutoConfiguration {

    @Autowired
    private TongProperties tongProperties;

    @Bean
    public TongService tongService() {
        return new TongService(tongProperties);
    }
}
